package com.qingke.besuper.command;

import java.util.HashMap;
import java.util.Map;

import com.qingke.besuper.command.impl.ExitCommand;
import com.qingke.besuper.command.impl.HelpSystemCommand;
import com.qingke.besuper.command.impl.LoginCommand;
import com.qingke.besuper.command.impl.RegisterCommand;
import com.qingke.besuper.util.BeSuperConsole;

public class SystemCommandFactory extends CommandFactory{
	public static Map<CommandCode,Class<? extends Command>> systemMap = new HashMap<>();
	static {
		systemMap.put(CommandCode.LOGIN, LoginCommand.class);
		systemMap.put(CommandCode.REGISTER, RegisterCommand.class);
		systemMap.put(CommandCode.HELP, HelpSystemCommand.class);
		systemMap.put(CommandCode.EXIT, ExitCommand.class);
	}
	public Command buildCommand(CommandCode cmdCode){
		Command command=null;
		Class<?> commandClass=null;
		commandClass=systemMap.get(cmdCode);
		if(commandClass==null){
			BeSuperConsole.println("Please login first.");
			return null;
		}
		try {
			command=(Command) commandClass.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return command;
	}
}
